package com.android.infantschool.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.infantschool.R;
import com.android.infantschool.bean.BaseBean;
import com.android.infantschool.bean.ResponseBean;
import com.android.infantschool.model.mvp.presenter.AboutPresenter;
import com.android.infantschool.model.mvp.presenter.AboutPresenterImpl;
import com.android.infantschool.model.mvp.view.AboutView;
import com.android.infantschool.util.ToastUtil;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Administrator
 * @particulars
 * @time 2019\6\22 0022 10:29
 * @class describe
 */
public class AboutActivity extends BaseActivity implements AboutView {

    @BindView(R.id.img_back)
    public ImageView ivBack;
    @BindView(R.id.tv_title)
    public TextView tvTitle;
    @BindView(R.id.title)
    public RelativeLayout rlTitle;
    @BindView(R.id.tv_content)
    public TextView tvContent;

    private AboutPresenter presenter = null;

    public static Intent newIntent(Activity activity) {
        Intent intent = new Intent(activity, AboutActivity.class);
        return intent;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        presenter = new AboutPresenterImpl(this);
        rlTitle.setPadding(0, this.height, 0, 0);
        tvTitle.setText("关于我们");
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (presenter != null) {
            this.showLoading();
            Map<String, String> map = new HashMap<>();
            presenter.getAbout(map);
        }
    }

    @OnClick(R.id.img_back)
    public void onViewClicked() {
        this.finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            presenter.onDestroy();
            presenter = null;
        }
    }

    @Override
    public void errorAbout(String error) {
        this.dismissLoading();
        ToastUtil.showShortToast(this, "网络异常:" + error);
    }

    @Override
    public void successAbout(BaseBean baseBean) {
        this.dismissLoading();
        ResponseBean responseBean = (ResponseBean) baseBean;
        if (responseBean.getCode() == 0) {
            tvContent.setText((String) responseBean.getData());
        } else {
            ToastUtil.showShortToast(this, "请求失败:" + responseBean.getMsg());
        }
    }
}
